<!--{template header}-->

<!--{if $_GET[op]=='edit'}-->

<form method="post" action="cp.php?ac=mtag&op=edit&tagid=$mtag[tagid]">
<!--{if $_SGLOBAL[inajax]}-->
	<h1>设置选吧</h1>
	<a href="javascript:hideMenu();" class="float_del" title="关闭">关闭</a>
	<div class="popupmenu_inner">
<!--{/if}-->
<table>
	<tr>
		<td colspan="2"><strong>$mtag[tagname]</strong></td>
	</tr>
	<tr>
		<th><label for="pic">封面图片：</label></th>
		<td><input id="pic" type="text" name="pic" value="$mtag[pic]" size="30" /><br />http:// 开头的图片地址</td>
	</tr>
	<tr>
		<th><label for="announcement">公告：</label></th>
		<td><textarea id="announcement" name="announcement" cols="40" rows="5">$mtag[announcement]</textarea></td>
	</tr>
	<!--{if $mtag['isadmin']}-->
	<tr>
		<th>吧主：</th>
		<td>
		<!--{if $moderator[0]}-->
		<input type="text" name="moderator[0]" value="$moderator[0]" size="10" readonly="true">
		<!--{else}-->
		<input type="text" name="moderator[0]" value="$moderator[0]" size="10">
		<!--{/if}-->
		<input type="text" name="moderator[1]" value="$moderator[1]" size="10">
		<input type="text" name="moderator[2]" value="$moderator[2]" size="10">
		<input type="text" name="moderator[3]" value="$moderator[3]" size="10">
		<input type="text" name="moderator[4]" value="$moderator[4]" size="10"><br>
		<input type="text" name="moderator[5]" value="$moderator[5]" size="10">
		<input type="text" name="moderator[6]" value="$moderator[6]" size="10">
		<input type="text" name="moderator[7]" value="$moderator[7]" size="10">
		<input type="text" name="moderator[8]" value="$moderator[8]" size="10">
		<input type="text" name="moderator[9]" value="$moderator[9]" size="10"><br>
		只能从成员列表中选，最多10个，第1位为主版主，不能被更改
		</td>
	</tr>
	<!--{/if}-->
	<tr>
		<th>&nbsp;</th>
		<td>
		<input type="hidden" name="refer" value="$_SGLOBAL[refer]" />
		<input type="hidden" name="editsubmit" value="true" />
		<input type="submit" name="btnsubmit" value="提交编辑" class="submit" />&nbsp;
		</td>
	</tr>
</table>
</form>

<!--{elseif $_GET[op]=='join'}-->

<div id="$mtag[tagid]" <!--{if !$_SGLOBAL[inajax]}-->class="inpage"<!--{/if}-->>
<form id="joinform" name="joinform" method="post" action="cp.php?ac=mtag&op=join&tagid=$mtag[tagid]">
	<h1>确定加入该选吧吗？</h1>
	<p class="btn_line">
		<input type="hidden" name="refer" value="$_SGLOBAL[refer]" />
		<!--{if $_SGLOBAL[inajax]}-->
		<input type="hidden" name="joinsubmit" value="true" />
		<input type="button" name="joinsubmit_btn" value="加入" class="submit" onclick="ajaxpost('joinform', '$mtag[tagid]', 'mtag_join')" />&nbsp;
		<button name="btncancel" type="button" class="button" onclick="hideMenu()">取消</button>
		<!--{else}-->
		<input type="submit" name="joinsubmit" value="加入" class="submit" />
		<!--{/if}-->
	</p>
</form>
</div>
<!--{elseif $_GET[op]=='out'}-->
<div id="$mtag[tagid]" <!--{if !$_SGLOBAL[inajax]}-->class="inpage"<!--{/if}-->>
<form id="outform" name="outform" method="post" action="cp.php?ac=mtag&op=out&tagid=$mtag[tagid]">
	<h1>确定要退出该选吧吗？</h1>
	<p class="btn_line">
		<input type="hidden" name="refer" value="$_SGLOBAL[refer]" />
		<!--{if $_SGLOBAL[inajax]}-->
		<input type="hidden" name="outsubmit" value="true" />
		<input type="button" name="outsubmit_btn" value="退出" class="submit" onclick="ajaxpost('outform', '$mtag[tagid]', 'mtag_join')" />&nbsp;
		<button name="btncancel" type="button" class="button" onclick="hideMenu()">取消</button>
		<!--{else}-->
		<input type="submit" name="outsubmit" value="退出" class="submit" />
		<!--{/if}-->
	</p>
</form>
</div>
<!--{else}-->

<!--{if $_SGLOBAL['guidemode']}-->
<!--{template space_guide}-->
<!--{else}-->
<!--{template cp_header}-->
<!--{/if}-->

<form method="post" action="cp.php?ac=mtag&op=" class="c_form" onsubmit="closeMsg();">
	<table cellspacing="0" cellpadding="0" class="formtable" width="100%">
		<caption style="padding-bottom: 0; width: 100%;">
			<h2>我的选吧</h2>
			<p>选吧，就是自己选择的志同道合的交流圈。<br />在吧内，不仅可以结识与你有相同选择的朋友，更可以一起交流话题。</p>
		</caption>
	</table>
	<!--{eval $divjs = '';}-->
	<!--{loop $fields $fieldid $fvalue}-->
	<table cellspacing="0" cellpadding="0" class="formtable">
		<caption style="padding-bottom: 0;">
			<h2>$fvalue[title]</h2>
			<!--{if $fvalue['note']}--><p>$fvalue[note]</p><!--{/if}-->
		</caption>
		<tr>
			<!--{if is_array($fvalue[formhtml])}-->
			<td style="width: 224px; vertical-align: top;">	
				<ul id="mtag_{$fieldid}_ul" class="post_list line_list" style="margin-bottom: 8px;">
				<!--{if $fvalue[formhtml]}-->
				<!--{loop $fvalue[formhtml] $rowid $rowvalue}-->
					<li>$rowvalue</li>
				<!--{/loop}-->
				<!--{else}-->
					<li class="gray">请在右侧选择或添加选吧 &raquo;</li>
				<!--{/if}-->
				</ul>
				<!--{if !$_SGLOBAL['guidemode']}-->
				<button type="button" class="submit" onclick="document.getElementById('mtagsubmit').click();">保存</button>
				<!--{/if}-->
			</td>
			<td style="padding-right: 0; padding-top: 0; vertical-align: top;">
				<div style="float: right; padding: 8px; background: #F9F9F9;">
					<!--{if $hotlist[$fieldid]}-->
					<p style="padding: 4px 0;" class="gray">加入现有的选吧：</p>
					<select name="hot_mtag_$fieldid" onchange="mtagAdd('$fieldid', '$fvalue[inputnum]', this.value);">
					<option value="">--- 成员数排行 ---</option>
					<!--{loop $hotlist[$fieldid] $hotvalue}-->
					<option value="$hotvalue[tagname]">$hotvalue[tagname] ($hotvalue[membernum]人)</option>
					<!--{/loop}-->
					</select>					
					<!--{/if}-->
					<p style="padding: 4px 0;" class="gray">创建新的选吧：</p>
					<table cellspacing="0" cellpadding="0">
						<tr>
							<td style="padding: 0;"><input type="text" name="mtag_{$fieldid}_name" id="mtag_{$fieldid}_name" value="" class="t_input" style="width: 160px; border-right: none;" /></td>
							<td style="padding: 0;"><a href="javascript:;" onclick="mtagSearch('$fieldid', '$fvalue[inputnum]');"><img src="image/search_btn.gif" alt="搜索" title="从现有的选吧中搜索"/></a></td>
							<td style="padding: 0 0 0 3px;"><input class="button" type="button" value="添加" onclick="mtagAdd('$fieldid', '$fvalue[inputnum]');" /></td>
						</tr>
					</table>
					<div id="mtagresult_$fieldid" class="ajax_selector" style="display: none;">
						<div class="ajax_selector_option" style="width: 181px;height: 166px;">
							<ul id="mtagresult_{$fieldid}_ul" class="blocklink"></ul>
						</div>
					</div>
					<p id="mtagstatus_$fieldid" style="padding: 4px 0;"></p>
				</div>
			</td>
			<!--{else}-->
			<td>
				<div id="mtagresult_$fieldid"></div>
				$fvalue[formhtml]
				<!--{if !$_SGLOBAL['guidemode']}-->
				&nbsp; <button type="button" class="submit" onclick="document.getElementById('mtagsubmit').click();">保存</button>
				<!--{/if}-->
			</td>
			<!--{/if}-->
		</tr>
	</table>
	<!--{/loop}-->
	<br>
	<!--{if $_SGLOBAL['guidemode']}-->
	<table cellspacing="0" cellpadding="0" class="formtable">
		<tr>
		<td><a href="space.php?do=home&view=guide&step=1">返回</a></td>
		<td align="center">
		<input type="hidden" name="guidemode" value="1">
		<input type="submit" id="mtagsubmit" name="mtagsubmit" value="下一步" class="submit" />
		 </td>
		 <td align="right"><a href="space.php?do=home&view=guide&step=3">跳过&gt;&gt;</a></td>
		 </tr>
	</table>
	<!--{else}-->
	<div style="display: none;"><input type="submit" id="mtagsubmit" name="mtagsubmit" value="提交保存"></div>
	<!--{/if}-->
</form>

<div class="f_status s_clear">
	<a href="javascript:;" onclick="window.scrollTo(0,0);" id="a_top" title="TOP">TOP</a>
</div>

<script type="text/javascript">
	var isModify = false;
	var thetimer = '';
	function mtagAdd(id, inputnum, selectname) {
		var str = '';
		objmtag = $('mtag_'+id+'_name');
		
		if(selectname) {
			var mtagname = selectname;
		} else {
			var mtagname = objmtag.value;
		}
		var objstatus = $('mtagstatus_'+id);

		//mtagname = mtagname.replace(/[ 　]/g, '');
		if(strLen(mtagname) >= 40 || strLen(mtagname) <= 0) {
			shadowShow(objstatus, '选项请保证在1-40个字符之间');
		} else {
			var arrayelement = getElementsByName_iefix('input', 'mtag['+id+'][]');
			var badd = true;
			window.onbeforeunload = showUnload;
			isModify = true;
			if(arrayelement.length < inputnum) {
				for(i = 0; i < arrayelement.length; i++) {
					if(arrayelement[i].value == mtagname) {
						badd = false; 
						break;
					}
				}
				if(badd) {
					var mtagname = cnCode(mtagname);
					var x = new Ajax();
					x.get('cp.php?ac=mtag&op=searchmtag&inajax=1&fieldid='+id+'&mtagname='+mtagname, function(s){
						var newli = document.createElement("li");
						newli.innerHTML = s;
						$('mtag_'+id+'_ul').appendChild(newli);
						
						objstatus.innerHTML = '';
						objmtag.value = '';
					});
				} else {
					shadowShow(objstatus, '选项已经存在');
				}
			} else {
				shadowShow(objstatus, '最多支持 '+inputnum+' 个');
			}
		}
		objmtag.focus();
	}
	function mtagSearch(id, inputnum) {
		var str = '';
		var objmtag = $('mtag_'+id+'_name');
		var objstatus = $('mtagstatus_'+id);
		closeMsg();
		objmtag.value = objmtag.value.replace(/[ 　]/g, '');
		if(strLen(objmtag.value) >= 40 || strLen(objmtag.value) <= 2) {
			shadowShow(objstatus, '选项请保证在3-39个字符之间');
		} else {
			var mtagname = cnCode(objmtag.value);
			var x = new Ajax();
			x.get('cp.php?ac=mtag&op=searchmtag&inajax=1&fieldid='+id+'&mtagname='+mtagname+'&like=1&inputnum='+inputnum, function(s){
				if(s != '') {
					$('mtagresult_'+id).style.display = '';
					$('mtagresult_'+id+'_ul').innerHTML = s;
					objstatus.innerHTML = '';
				} else {
					shadowShow(objstatus, '查询不到结果');
				}
				if(isModify) window.onbeforeunload = showUnload;
			});
		}
		objmtag.focus();
	}
	function mtagDel(obj) {
		obj.parentNode.parentNode.removeChild(obj.parentNode);
		window.onbeforeunload = showUnload;
		isModify = true;
	}
	function mtagChoose(id, str) {
		$('mtag_'+id+'_name').value = str;
		$('mtagresult_'+id).style.display = 'none';
		
	}
	function postsearchmtag(event, id, inputnum) {
		if(event.keyCode == 13) {
			mtagAdd(id, inputnum);
			return false;
		}
	}
	function getElementsByName_iefix(tag, name) { 
		var elem = document.getElementsByTagName(tag); 
		var arr = new Array(); 
		for(i = 0, iarr = 0; i < elem.length; i++) { 
			att = elem[i].getAttribute("name"); 
			if(att == name) { 
				arr[iarr] = elem[i]; 
				iarr++; 
			} 
		} 
		return arr; 
	}
	function strLen(str) {
		var charset = document.charset; 
		var len = 0;
		for(var i = 0; i < str.length; i++) {
			len += str.charCodeAt(i) < 0 || str.charCodeAt(i) > 255 ? (charset == "utf-8" ? 3 : 2) : 1;
		}
		return len;
	}
	function shadowShow(obj, str) {
		obj.innerHTML = str;
		setTimeout(function(){obj.innerHTML=''}, 3000);
	}
	function showUnload() {
		return '选吧还没有提交保存!';
	}
	function closeMsg() {
		window.onbeforeunload = null;
		return true;
	}
</script>
<!--{/if}-->
<!--{template footer}-->